#coding=utf8
import itchat
from itchat.content import *
# tuling plugin can be get here:
# https://github.com/littlecodersh/EasierLife/tree/master/Plugins/Tuling
# from tuling import get_response
import requests

def get_response(msg):
    apiUrl = 'http://www.tuling123.com/openapi/api'
    data = {
        'key'    : '090609a1c6234a27abbfe31ca670567e',#这里是你申请的key
        'info'   : msg,
        'userid' : 'wechat-robot',
    }
    r = requests.post(apiUrl, data=data).json()
    return r.get('text')

# 消息类型 TEXT PICTURE RECORDING CARD MAP FRIENDS [NOTE, SHARING, ATTACHMENT, VIDEO]

# 给指定人发送消息  itchat.send('Message Content', 'toUserName')
# 文件传输助手 filehelper



# 文本消息
@itchat.msg_register(TEXT)
def print_content(msg):
    # 原封不动回复   return msg['Text']
    return "本人离线，人工智能自动回复:" + get_response(msg['Text'])

# 群组文本信息
@itchat.msg_register(TEXT, isGroupChat=True)
def print_content(msg):
    print("收到群消息:")
    print(msg.isAt)
    print(msg.actualNickName)
    print(msg.text)
    if msg.isAt:
        var = "@" + msg.actualNickName + " " + get_response(msg['Text'])
        print("回复群消息:")
        print(var)
        return var

#return get_response(msg['Text'])






itchat.auto_login(True)
itchat.run()
